#!/bin/bash
echo -e -n "\e[31;40m 必须要先设置主机名且必须相同(y/n): \e[0m"
systemctl stop firewalld.service
systemctl disable firewalld.service
iptables -F
iptables -X
iptables -Z
service iptables save

sed -i '$a192.168.200.11 mysql1' /etc/hosts
sed -i '$a192.168.200.12 mysql2' /etc/hosts
sed -i '$a192.168.200.13 mycat' /etc/hosts

PASSWORD=""
cd /etc/yum.repos.d/

rm -rvf *

cat >>centos.repo<<OK
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enable=1
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
gpgcheck=0
enable=1
[zabbix]
name=zabbix
baseurl=file:///opt/zabbix
enabled=1
gpgcheck=0
OK

cd

mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/
mkdir /opt/centos
cp -rvf /mnt/* /opt/centos
umount /mnt/

cp -rvf /root/gpmall-repo /opt/
cp -rvf /root/zabbix /opt/

yum clean all
yum install vsftpd -y
yum install -y mariadb mariadb-server
sed -i '$ianon_root=/opt/' /etc/vsftpd/vsftpd.conf
yum install httpd -y
yum install -y mariadb-server mariadb
yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent

systemctl restart mariadb
systemctl restart vsftpd
systemctl enable vsftpd
systemctl restart httpd
systemctl enable httpd
systemctl enable mariadb


sed -i '6i [mysqld]' /etc/my.cnf
sed -i '7i log_bin = mysql-bin' /etc/my.cnf
sed -i '8i binlog_ignore_db = mysql' /etc/my.cnf
sed -i '9i server_id = 10' /etc/my.cnf
sed -i '10i innodb_strict_mode = 0' /etc/my.cnf

systemctl restart mariadb


sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config


# execute sql stat 
sql1="create database zabbix character set utf8 collate utf8_bin;"
sql2="grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';"
sql3="grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';"
mysql -uroot -p${PASSWORD} -e "${sql1}"
mysql -uroot -p${PASSWORD} -e "${sql2}"
mysql -uroot -p${PASSWORD} -e "${sql3}"

cd /usr/share/doc/zabbix-server-mysql-3.4.15/

systemctl restart mariadb

zcat create.sql.gz | mysql -uroot -p zabbix

sed -i '876i date.timezone = PRC' /etc/php.ini

sed -i '14i php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
systemctl restart httpd

sed -i 's/# DBHost=localhost/DBHost=localhost/g' /etc/zabbix/zabbix_server.conf
sed -i 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
sed -i '132i DBSocket=/var/lib/mysql/mysql.sock' /etc/zabbix/zabbix_server.conf
systemctl restart zabbix-server
yum install -y net-tools
netstat -ntpl





